<template>
  <div>
    <el-container>
      <el-header class="homeHeader">
        <div class="title">
          WELCOME
        </div> 
       <div>
         <el-button icon="el-icon-bell" type="text" size="normal" 
         style="margin-right: 8px;color:black" @click="goChat"></el-button>
         <el-dropdown class="userInfo" @command="commandHandler">
          <span class="el-dropdown-link">
            {{user.nickName}}<i><img src="../assets/cute.jpeg" /></i>
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item command="userInfo">個人情報</el-dropdown-item>
            <el-dropdown-item command="setting">設置</el-dropdown-item>
            <el-dropdown-item command="logOut">ログアウト</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
       </div>
      </el-header>
      <el-container>
        <el-aside width="250px">
          <el-menu router unique-opened>
            <div v-for="(item, index) in routes" v-bind:key="index">
              <el-submenu :index="index+''" v-if="!item.hidden">
                <template slot="title">
                  <i :class="item.icon" style="color: #c4c488;margin-right: 5px"></i>
                  <span>{{item.name}}</span>
                 </template>
                <el-menu-item :index="children.path" v-for="(children,indexj) in item.children" 
                v-bind:key="indexj">{{children.name}}</el-menu-item> 
              </el-submenu>
            </div>
          </el-menu>
        </el-aside>
        <el-main>
          <el-breadcrumb v-if="this.$router.currentRoute.name!='MyHome'" separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/myHome' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>{{this.$router.currentRoute.name}}</el-breadcrumb-item>
          </el-breadcrumb>
          <div class="homeWelcome" v-if="this.$router.currentRoute.name=='MyHome'">
            WELCOME
          </div>
          <router-view class="homeRouterView"/>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  name: "MyHome",
  data(){
    return{
      user: JSON.parse(window.sessionStorage.getItem('user'))
    }

  },
  computed:{
    routes(){
       return this.$store.state.routes;
    }
  },
  methods:{
    goChat(){
      this.$router.push('/chat');
    },
    commandHandler(command){
      if(command=="logOut"){
        // 注销登陆
        this.postRequest("/user/goLogout",null).then((resp) => {
          if (resp) {
              // 清空用户信息
              window.sessionStorage.removeItem("token");
              window.sessionStorage.removeItem("user");
              // 返回登陆页
              this.$router.replace("/");

          }
        })
      }
    }
  }
};
</script>

<style>
.homeHeader{
  background-color: #cdcdad;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 15px;
  box-sizing: border-box;
}
.homeHeader.title{
  font-size: 30px;
  font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
  color: chocolate;
}
.homeHeader.user{
  cursor: pointer;
}
.el-dropdown-link img {
  width: 48px;
  height: 48px;
  border-radius: 24px;
  margin-left: 8px;
}
.homeWelcome{
  text-align: center;
  font-size: 30px;
  font-family: Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;
  color: #409eff;
  padding-top: 50px;
}
.homeRouterView{
  margin-top: 15px;
}

</style>